﻿using HCQ2WebAPI_Logic.BaseAPIController;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HCQ2WebAPI_Logic.BaseAPIController;
using HCQ2_Model.ViewModel.WebAPI;
using System.Web.Http;
using HCQ2_Model.DocModel;
using HCQ2WebAPI_Logic.Model;
using HCQ2_Common.Constant;
using HCQ2_Model.DocModel.APIResultModel;
using HCQ2_Model.ViewModel;
using HCQ2_Model.APPModel.ParamModel;
using HCQ2_Model;
using HCQ2_Model.VR.Params;

namespace HCQ2WebAPI_Logic.DocumentController
{
    /// <summary>
    ///  待审核控制器
    /// </summary>
    public class ApproveVRController: BaseWeiXinApiLogic
    {
        //**************************************************1.0 待审核************************************
        #region 1.0  获取待审核 + async Task<WebApiResultJsonModel> GetWaitApprove(DocListParam model)
        /// <summary>
        ///  获取待审核
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel GetWaitApprove(DocListParam model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception,getErrorMessage(ModelState), null);
            //判断当前用户是否拥有审核权限
            int userId = HCQ2UI_Helper.Session.SysPermissSession.ChangeIdByGuid(model.userid);
            if(!operateContext.bllSession.T_DocumentInfo.IsApproveLimit(userId))
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "您没有审核权限，不允许查看待审核~", null);
            model.docStatus = 8;//标记为获取全部待审核
            List<GoodsListModel> list = operateContext.bllSession.T_DocumentInfo.GetSynchronMyVR(model, 0);
            TableModel tModel = new TableModel()
            {
                total = operateContext.bllSession.T_DocumentInfo.GetSynchronMyVRCount(model, 0),
                rows = list
            };
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "获取文档列表成功~", tModel);
        }
        #endregion

        #region 1.1  添加素材/作品 录屏url地址 + async Task<WebApiResultJsonModel> AddVideoUrl(VideoUrlModel model)
        /// <summary>
        ///  添加素材/作品 录屏url地址
        /// </summary>
        /// <param name="model">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel AddVideoUrl(VideoUrlModel model)
        {
            if (!ModelState.IsValid)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, getErrorMessage(ModelState), null);
            //1.0 判断作品是否存在
            int fileCount = operateContext.bllSession.T_DocumentInfo.SelectCount(s => s.file_id.Equals(model.file_id));
            if(fileCount<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Exception, "指定的素材/作品不存在~", "");
            //2.0 更新录屏url
            operateContext.bllSession.T_DocumentInfo.Modify(new T_DocumentInfo { video_url = model.video_url }, s => s.file_id.Equals(model.file_id), "video_url");
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "录屏地址指定成功~", "");
        }
        #endregion

        //**************************************************2.0 合伙人协议************************************
        #region 2.0  获取合伙人协议 + async Task<WebApiResultJsonModel> GetFouderPact(FouderPactParam param)
        /// <summary>
        ///  获取合伙人协议
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        [HttpPost]
        public WebApiResultJsonModel GetFouderPact(FouderPactParam param)
        {
            if(param.id<=0 && param.folder_id<=0)
                return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "", string.Empty);
            string dealNote = string.Empty;
            if (param.id>0)
                dealNote = operateContext.bllSession.T_VRFounderDeal.FindSingle(s => s.id == param.id)?.deal_note;
            else
                dealNote = operateContext.bllSession.T_VRFounderDeal.FindSingle(s => s.folder_id == param.folder_id)?.deal_note;
            return ApiResultJsonModel.RedirectWebApi(WebResultCode.Ok, "", dealNote);
        }
        #endregion
    }
}